package com.infitecs.eyas.security.model;

import com.infitecs.eyas.common.ajax.DataTablesPage;
import com.infitecs.eyas.util.Dict;
import org.hibernate.validator.constraints.NotBlank;

import java.util.List;

/**
 * @author gaoxinyu
 */
public class User extends DataTablesPage {

    public User() {
    }

    public User(String userId) {
        this.userId = userId;
    }

    private String userId;
    @NotBlank(message = "{user.username.NotBlank}")
    private String username;
    private String nickname;
    private String password;
    private boolean rememberMe;
    private List<Role> roleList;
    private String ip;
    private String ipFlag;
    private String effectiveDate;
    private String createDate;

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public boolean isRememberMe() {
        return rememberMe;
    }

    public void setRememberMe(boolean rememberMe) {
        this.rememberMe = rememberMe;
    }

    public List<Role> getRoleList() {
        return roleList;
    }

    public void setRoleList(List<Role> roleList) {
        this.roleList = roleList;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getIpFlag() {
        return ipFlag;
    }

    public void setIpFlag(String ipFlag) {
        this.ipFlag = ipFlag;
    }

    public String getEffectiveDate() {
        return effectiveDate;
    }

    public void setEffectiveDate(String effectiveDate) {
        this.effectiveDate = effectiveDate;
    }

    public String getCreateDate() {
        return createDate;
    }

    public void setCreateDate(String createDate) {
        this.createDate = createDate;
    }

    public boolean isAdmin() {
        if (roleList == null) {
            return false;
        }
        for (Role role : roleList) {
            if (role.getRoleId().equals(Dict.ROLE_SUPPER_ADMIN) || role.getRoleId().equals(Dict.ROLE_SYSTEM_ADMIN)) {
                return true;
            }
        }
        return false;
    }
}
